<template>
  <div class="">
    <h1>个人中心页面</h1>
    <h1>{{ $store.state.user }}</h1>
    <button @click="exit">退出登录</button>
  </div>
</template>

<script>
export default {
  data() {
    return {};
  },
  mounted() {},
  methods: {
    exit() {
      this.$store.commit("exit");
      //调用vuex里exit方法
      this.$router.push("/login");
      //跳转到login页面
    },
  },
  components: {},
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      if (vm.$store.state.user != "") {
        next();
      } else {
        next("/login");
      }
    });
  },
};
</script>

<style lang="scss"></style>
